package com.ease.concurrent.volat;

import java.util.concurrent.TimeUnit;

/**
 * @author: chenhs
 * @date: Created in 20:30 2019/11/5
 **/
public class VisibilityDemo2 {
    /**状态标识*/
    private static volatile boolean is = true;

    public static void main(String[] args) {

        VisibilityDemo2 demo = new VisibilityDemo2();

        new Thread(()->{
            int i = 0;
            while (VisibilityDemo2.is) {
                i++;
            }
            System.out.println(i);
        }).start();

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        VisibilityDemo2.is = false;
        System.out.println("被置为false了！");

    }

}
